"""
@name : 文本操作练习
@author : wangaokang
@projectname: pythonProject6
"""
def ip_create():
    import random
    global ipshow
    ipshow = 0

    with open("ips.txt","w+") as fp:
        for i in range(120000):

            str1 = random.randint(1,256)
            ip = f'172.25.254.{str1}'
            fp.write(ip + '\n')

    with open("ips.txt","r+") as fp:
        ipshow = fp.readlines()

#创建文本函数
ip_create()

#新建字典
ip_alive = {}
for ip in ipshow:

    #检验IP是否在字典中
    if ip in ip_alive:
        ip_alive[ip] +=1
    else:
        ip_alive[ip] = 1

      #字典排序模板
result =sorted(ip_alive.items(),key=lambda x: x[1], reverse=True)[:10]
print(f"前十是：{result}" )